package com.garen.sys.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.garen.common.BaseAction;
import com.garen.common.MsgBean;
import com.garen.common.PageBean;
import com.garen.sys.biz.IFireUserBiz;
import com.garen.sys.entity.FireUser;
import com.garen.sys.filter.SysFilter;



@Controller
@RequestMapping("/sys")
public final class FireUserAction extends BaseAction {

	protected static Log log = LogFactory.getLog(FireUserAction.class);

	@Autowired
	private IFireUserBiz iFireUserBiz;

	@RequestMapping("/fireuser/json")
	public ModelAndView json(PageBean<FireUser> pb, FireUser fireUser) {
		iFireUserBiz.getFireUserList(pb, fireUser);
		return Json(pb);
	}

	@RequestMapping("/fireuser/get")
	public ModelAndView get(FireUser fireUser) {
		MsgBean mbean = SysFilter.getMsgBean();
		if (fireUser.getUserId() == null) {
			mbean.setRetInfo(-1, "参数不能为空!");
			return Json(mbean);
		}
		mbean.setObj(iFireUserBiz.getFireUser(fireUser));
		return Json(mbean);
	}

	@RequestMapping("/fireuser/getcountandduty")
	public ModelAndView getcountandduty(String org_id) {
		MsgBean mbean = SysFilter.getMsgBean();
		if (org_id == null) {
			mbean.setRetInfo(-1, "参数不能为空!");
			return Json(mbean);
		}
		mbean.setObj(iFireUserBiz.getcountandduty(org_id));
		return Json(mbean);
	}

	@RequestMapping("/fireuser/boxJson")
	public ModelAndView boxJson(FireUser fireUser) {
		return Json(iFireUserBiz.getFireUserList(fireUser));
	}

	@RequestMapping("/fireuser/edit")
	public ModelAndView edit(ModelAndView mav, FireUser fireUser) {
		mav.setViewName("sys/FireUserEdit");
		if (fireUser.getUserId() != null) {
			fireUser = iFireUserBiz.getFireUser(fireUser);
		}
		mav.addObject("fireUser", fireUser);
		return mav;
	}

	@RequestMapping("/fireuser/save")
	public ModelAndView save(FireUser fireUser) {
		MsgBean mbean = SysFilter.getMsgBean(0, "保存成功 !");
		iFireUserBiz.saveFireUser(mbean, fireUser);
		return Json(mbean);
	}

	@RequestMapping("/fireuser/del")
	public ModelAndView del(FireUser fireUser) {
		MsgBean mbean = SysFilter.getMsgBean(0, "删除成功 !");
		iFireUserBiz.delFireUser(mbean, fireUser);
		return Json(mbean);
	}

//	@RequestMapping("/fireuser/push")
//	public ModelAndView push() {
//		JPushClient jpushClient = new JPushClient("d3d3848752b2ba62239b0be0", "ebb192814bacf185f317504c", null,
//				ClientConfig.getInstance());
//
//		// For push, all you need do is to build PushPayload object.
//		PushPayload payload = buildPushObject_all_all_alert();
//
//		try {
//			PushResult result = jpushClient.sendPush(payload);
//			// LOG.info("Got result - " + result);
//
//		} catch (APIConnectionException e) {
//			// Connection error, should retry later
//			// LOG.error("Connection error, should retry later", e);
//
//		} catch (APIRequestException e) {
//			// Should review the error, and fix the request
//			System.out.println("Should review the error, and fix the request" + e.toString());
//
//		}
//		return null;
//	}
//
//	public static PushPayload buildPushObject_all_all_alert() {
//		return PushPayload.alertAll("test");
//	}

}
